package cn.zz.camerasdk.utils;

/**
 * author: zhu on 2017/7/7 16:56
 * email: mackkill@gmail.com
 */

import android.content.Context;
import android.content.res.Resources;

public class MResource {
    public static final String layout = "layout";
    public static final String string = "string";
    public static final String style = "style";
    public static final String anim = "anim";
    public static final String attr = "attr";
    public static final String raw = "raw";
    public static final String id = "id";
    public static final String drawable = "drawable";

    public MResource() {
    }

    public static int getIdByName(Context context, String className, String name) {
        String packageName = context.getPackageName();
        Class r = null;
        int id = 0;

        try {
            r = Class.forName(packageName + ".R");
            Class[] e = r.getClasses();
            Class desireClass = null;

            for(int i = 0; i < e.length; ++i) {
                if(e[i].getName().split("\\$")[1].equals(className)) {
                    desireClass = e[i];
                    break;
                }
            }

            if(desireClass != null) {
                id = desireClass.getField(name).getInt(desireClass);
            }
        } catch (ClassNotFoundException var9) {
            var9.printStackTrace();
        } catch (IllegalArgumentException var10) {
            var10.printStackTrace();
        } catch (SecurityException var11) {
            var11.printStackTrace();
        } catch (IllegalAccessException var12) {
            var12.printStackTrace();
        } catch (NoSuchFieldException var13) {
            var13.printStackTrace();
        }

        return id;
    }

    public static int getIdRes(Context context, String name) {
        Resources resources = context.getResources();
        int indentify = resources.getIdentifier(context.getPackageName() + ":id/" + name, (String)null, (String)null);
        return indentify;
    }
}